package com.gwt.client;

import java.util.List;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.cellview.client.CellList;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.ScrollPanel;



public class Instruments {

	
	
	ItemCell itemCell = new ItemCell();
	
	
	private ItemDatabaseServiceAsync itemDatabaseSvc = GWT.create(ItemDatabaseService.class);

/*	
	private final String classesList[]={"Brick1",
			"Brick2",
			"Brick3"
	};
	*/
	
	public Instruments(Panel panel){
		final CellList<ItemInfo> itemList = new CellList<ItemInfo>(itemCell,ItemInfo.KEY_PROVIDER);

/*
		List <ItemInfo> itemsInfo = new ArrayList<ItemInfo> ();

		for (String className : classesList) {
				itemsInfo.add(new ItemInfo(className));
		}
		itemList.setRowData(itemsInfo);
 */
		
		if (itemDatabaseSvc == null) {
			itemDatabaseSvc = GWT.create(ItemDatabaseService.class);
		}
		
		AsyncCallback<List <ItemInfo>> callback = new AsyncCallback<List <ItemInfo>>(){

			public void onFailure(Throwable caught) {
				Window.alert(caught.getMessage());
			}

			public void onSuccess(List<ItemInfo> result) {
				itemList.setRowData(result);
			}
			
		};
		
		itemDatabaseSvc.getClassesList(callback);
		
		itemList.setHeight("600px");
		ScrollPanel scrollPanel = new ScrollPanel(itemList);
		panel.add(scrollPanel);

		
		

	}
}
